home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / 5 / PIXELWOR / CPIXELWO.C < prev    next >
Text File  |  1992-01-01  |  7KB  |  226 lines

  1. /******************************************************************************
  2.  CPixelWorldPane.c
  3.  
  4.     Pixel World Pane Class, Version 1.0                (SUPERCLASS = CBitMapPane)
  5.     __________________________________________________________________________
  6.  
  7.     Ñ    Description
  8.         
  9.         The CPixelWorldPane class is a subclass of CBitMapPane (THINK Class 
  10.         Library 1.1) which uses a CPixelWorld to maintain a pane based on a 
  11.         color offscreen drawing environment.  An offscreen color graphics 
  12.         device (GDevice) and an offscreen color graphics port (CGrafPort) are 
  13.         used to maintain the offscreen world.  This implementation supports 
  14.         standard pixel depths of 1,2,4 and 8 bits.  Pixel depths of 16 and 32 
  15.         are not supported since the current implementation of CPixelWorld 
  16.         does not rely on 32-Bit QuickDraw features.  
  17.         
  18.         After creating an instance of the CPixelWorldPane class, initilaze the 
  19.         pane by calling the IPixelWorldPane() method with the same parameters 
  20.         that you normally pass to IPane() to initialize a CPane object, plus an 
  21.         additional two parameters:
  22.         
  23.         (1)    LongRect *aBounds
  24.         
  25.             This is the bounds rectangle for the offscreen world.
  26.         
  27.         (2)    CPixelWorld *aPixelWorld
  28.         
  29.             This is the pixel world which will be used to maintain the 
  30.             offscreen image.  You can create the pixel world yourself with
  31.             your own image and color table, or have a blank world created 
  32.             for you by passing NULL.  If you pass NULL, the pixel depth of the 
  33.             blank world will be set to the maximum pixel depth of all screens
  34.             that are currently active on your system.  A default color table 
  35.             for that pixel depth will be used for the blank offscreen world.  
  36.         
  37.         The GetPixelWorld() method returns a reference to the CPixelWorld
  38.         associated with the CPixelWorldPane.  The SetPixelWorld() method
  39.         allows you to assign a CPixelWorld to a CPixelWorldPane.  Before you
  40.         change the CPixelWorld associated with a CPixelWorldPane, call
  41.         GetPixelWorld() and dispose of the CPixelWorld currently associated
  42.         with the pane.  
  43.         
  44.         The Draw() and Dispose() methods of the CBitMapPane class have been 
  45.         overridden.  Use these methods as you would the corresponding methods 
  46.         of the superclass.  
  47.         
  48.     Ñ    Version History
  49.         
  50.         __________________________________________________________
  51.         Release Version:        1.0
  52.         Release Date:            January 1, 1992
  53.         
  54.         Implemented By:            Vincent R. Vann, Jr.
  55.                                 1901 Brickell Ave, B-410
  56.                                 Miami, Florida  33129  USA
  57.         
  58.         Compuserve Address:     76530,1242
  59.         Internet Address:        vvann@umbio.med.miami.edu
  60.                                 (129.171.65.204)
  61.         __________________________________________________________
  62.         
  63.     Ñ    License Agreement
  64.         
  65.         All portions of this source code are property of Vincent R. Vann, Jr.
  66.         I, Vincent R. Vann, Jr., grant you the right to freely distribute this 
  67.         source code and to use all or part of this source code in all software  
  68.         including commercial, freeware, shareware and private applications.  
  69.         However, all software that uses any part of or all of this source code 
  70.         must display a copyright notice indicating that either all of or 
  71.         portions of this source code are used in the software.  I also grant 
  72.         you permission to alter and make improvements to this source code, but 
  73.         only if all modifications are returned to me by whatever means are 
  74.         available, either in written or electronic form.  You must also accept 
  75.         that I retain the right to include any part of your modifications or 
  76.         all of your modifications in future releases of this source code.  The 
  77.         description and version history sections above may be ammended for 
  78.         documentation purposes.  This license agreement and the copyright 
  79.         notice below must be maintained intact and must be included with all 
  80.         distributions of this source code at all times.  
  81.         
  82.         This implementation is based in part on material copyrighted by Apple 
  83.         Computer, Inc. and Symantec Corporation.  
  84.         
  85.         Copyright ⌐ 1992 Vincent R. Vann, Jr.  All rights reserved.  
  86.         
  87.  ******************************************************************************/
  88.  
  89.  
  90. #include "CPixelWorldPane.h"
  91. #include "Exceptions.h"
  92. #include "Global.h"
  93. #include "LongQD.h"
  94.  
  95.  
  96. /**** C O N S T R U C T I O N / D E S T R U C T I O N   M E T H O D S ****/
  97.  
  98.  
  99. /******************************************************************************
  100.  IPixelWorldPane
  101.  
  102.         Initialize a PixelWorldPane object
  103.  ******************************************************************************/
  104.  
  105. void    CPixelWorldPane::IPixelWorldPane(
  106.     CView            *anEnclosure,
  107.     CBureaucrat        *aSupervisor,
  108.     short            aWidth,
  109.     short            aHeight,
  110.     short            aHEncl,
  111.     short            aVEncl,
  112.     SizingOption    aHSizing,
  113.     SizingOption    aVSizing,
  114.     LongRect        *aBounds,
  115.     CPixelWorld        *aPixelWorld)
  116. {
  117.     GDHandle        gdh;
  118.     PixMapHandle    pmap;
  119.     Rect            r;
  120.     short            pixelDepth;
  121.     
  122.     CPanorama::IPanorama( anEnclosure, aSupervisor,
  123.                           aWidth, aHeight, aHEncl, aVEncl, aHSizing, aVSizing);
  124.     
  125.     bounds = *aBounds;
  126.     position.h = bounds.left;
  127.     position.v = bounds.top;
  128.     
  129.     itsBitMap = NULL;
  130.     itsPixelWorld = NULL;
  131.     
  132.     if (aPixelWorld != NULL)            /* Use the existing pixel world */
  133.     {
  134.         itsPixelWorld = aPixelWorld;
  135.     }
  136.     else                            /* Create a default pixel world */
  137.     {
  138.         if (gSystem.hasColorQD)            /* World has color */
  139.         {
  140.             r = (**GrayRgn).rgnBBox;            /* Get rectangle that covers all screens */
  141.             
  142.             gdh = GetMaxDevice( &r);            /* Get device with maximum pixel depth */
  143.             pmap = (**gdh).gdPMap;                /* Get handle to devices pixel map */
  144.             
  145.             pixelDepth = (**pmap).pixelSize;    /* Grab its pixel depth setting */
  146.             if (pixelDepth > 8) pixelDepth = 8;    /* Pixel depths > 8 are not allowed */
  147.         }
  148.         else                            /* World is black and white */
  149.         {
  150.             pixelDepth = 1;                        /* Use a pixel depth of 1 */
  151.         }
  152.         
  153.         LongToQDRect( aBounds, &r);
  154.         
  155.         itsPixelWorld = new(CPixelWorld);
  156.         itsPixelWorld->IPixelWorld( pixelDepth, &r, NULL, NULL, 0);
  157.     }
  158.     
  159.     autoRefresh = FALSE;
  160. }
  161.  
  162.  
  163. /******************************************************************************
  164.  Dispose {OVERRIDE}
  165.  
  166.         Dispose of a PixelWorldPane
  167.  ******************************************************************************/
  168.  
  169. void    CPixelWorldPane::Dispose()
  170. {
  171.     if (itsPixelWorld != NULL) itsPixelWorld->Dispose();
  172.     
  173.     inherited::Dispose();
  174. }
  175.  
  176.  
  177. /******************************************************************************
  178.  SetPixelWorld
  179.  
  180.         Specify the PixelWorld associated with a PixelWorldPane
  181.  ******************************************************************************/
  182.  
  183. void    CPixelWorldPane::SetPixelWorld(
  184.     CPixelWorld*    aPixelWorld)
  185. {
  186.     itsPixelWorld = aPixelWorld;
  187. }
  188.  
  189.  
  190. /******************************************************************************
  191.  GetPixelWorld
  192.  
  193.         Return a reference to the PixelWorld associated with a PixelWorldPane
  194.  ******************************************************************************/
  195.  
  196. CPixelWorld*    CPixelWorldPane::GetPixelWorld()
  197. {
  198.     return( itsPixelWorld);
  199. }
  200.  
  201.  
  202. /******************************************************************************
  203.  Draw {OVERRIDE}
  204.  
  205.         Draw a PixelWorldPane
  206.  ******************************************************************************/
  207.  
  208. void    CPixelWorldPane::Draw(
  209.     Rect        *area)
  210. {
  211.     LongRect    lBounds, lArea;
  212.     Rect        bounds;
  213.     
  214.     if (itsPixelWorld != NULL)
  215.     {
  216.         itsPixelWorld->GetBounds( &lBounds);
  217.         LongToQDRect( &lBounds, &bounds);
  218.         
  219.         SectRect(area, &bounds, area);
  220.         
  221.         QDToFrameR( area, &lArea);
  222.         itsPixelWorld->CopyFrom( &lArea, &lArea, NULL);
  223.     }
  224. }
  225.  
  226.